<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:include="include/admin/adminHeader::html('工夹具全寿命智能管理系统')" ></head>
<body>
<div th:replace="include/admin/adminNavigator::html" ></div>
<script>
    $(function(){
        if(sessionStorage.jwt == null){
            self.location="login"
        }
        var data4Vue = {
            uri:'fixtures',
            beans: [],
            bean: { id: '', name: '',type:'',location:'',billno:""},
            pagination:{}
        };
        //ViewModel
        var vue = new Vue({
            el: '#workingArea',
            data: data4Vue,
            mounted:function(){ //mounted　表示这个 Vue 对象加载成功了
                this.list(0);
            },
            methods: {
                list:function(start){
                    var url =  this.uri+ "?start="+start;
                    axios.get(url).then(function(response) {
                        vue.pagination = response.data;
                        vue.beans = response.data.content   ;
                    });
                },
//                添加
                add:function () {
                    if(!checkEmpty(this.bean.id, "编号"))
                        return;
                    if (!checkEmpty(this.bean.name, "名称"))
                        return;
                    if (!checkEmpty(this.bean.type, "名称"))
                        return;

                    if (!checkEmpty(this.bean.location, "摆放位置"))
                        return;
                    if (!checkEmpty(this.bean.billno, "采购单号"))
                        return;
                    var url = this.uri;

                    axios.post(url,this.bean).then(function(response){
                        if (response.data.code==0){
                        alert("登记成功");
                        $('#myModal1').modal('hide');
                        vue.list(0);
                        vue.bean =  { id: '', name: '',type:'',location:'',billno:""}}
                        else
                        {
                            alert("该编号的工夹具已经存在!");
                        }
                    });
                },
//根据id获取数据
                get:function (id) {
                    var url = this.uri+"/"+id;
                    axios.get(url).then(function(response) {
                        vue.bean = response.data;
                    });
                },
//
                update:function () {

                    if (!checkEmpty(this.bean.name, "名称"))
                        return;
                    if (!checkEmpty(this.bean.type, "名称"))
                        return;

                    if (!checkEmpty(this.bean.location, "摆放位置"))
                        return;
                    if (!checkEmpty(this.bean.billno, "采购单号"))
                        return;
                    var url = this.uri;
                    axios.put(url,vue.bean).then(function(response){
                        alert("修改成功");
                        $('#myModal').modal('hide');
                        vue.list(0);
                        vue.bean =  { id: 0, username: '',password:'',name:'',tel:"",position:''};
                    });
                },
                b1:function () {
                    if(sessionStorage.jwt <= 600){
                        alert("您没有权限访问该界面")
                    }
                    else
                        self.location='admin_user';
                },


//                删除
                deleteBean:function (id) {
                    var url = this.uri+"/"+id;
                    axios.delete(url).then(function(response){
                        var d = confirm("是否要删除");
                        if(d===true) {
                            alert("删除成功");
                            vue.list(0);
                        }
                    });
                },
//                清理数据
                clear:function () {
                    vue.bean =  { id: 0, username: '',password:'',name:'',tel:"",position:''};
                },
                jump: function(page){
                    jump(page,vue); //定义在adminHeader.html 中
                },
                jumpByNumber: function(start){
                    jumpByNumber(start,vue);
                }
            }
        });

    });

</script>

<div class="page"  id="workingArea">


    <!-- 左部 -->
    <div class="page-content d-flex align-items-stretch" >


        <nav class="side-navbar">
            <!-- 头像名字部分-->
            <div class="sidebar-header d-flex align-items-center">
                <div class="avatar"><img src="img/admin/admin.jpg" alt="..." class="img-fluid rounded-circle"></div>
                <div class="title">
                    <h1 class="h4"><span th:if="${null!=session.user}">
                        <a href="#" th:text="${session.user.name}"></a>
                        </span></h1>
                    <p>Welcome</p>
                </div>
            </div>

            <!-- 左边菜单-->
            <span class="heading">管理</span>
            <ul class="list-unstyled">
                <li ><a href="admin_useinfo" >使用情况管理 </a></li>
                <li ><a href="admin_error" >故障预警管理 </a></li>
                <li class="active"><a href="admin_fixture" >工夹具管理</a></li>
                <li ><a href="#" @click="b1">用户管理</a></li>
            </ul>
        </nav>



        <!-- 右部部分 -->
        <div class="content-inner" >
            <!-- 管理标题-->
            <header class="page-header">
                <div class="container-fluid">
                    <h2 class="no-margin-bottom">工夹具信息管理</h2>
                </div>
            </header>

            <!-- 表格 -->

            <section class="tables" >
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="table-responsive" >
                                        <table class="table table-striped">
                                            <thead>
                                            <tr>
                                                <th >编号</th>
                                                <th >名称</th>
                                                <th >型号</th>
                                                <th>存放库位</th>
                                                <th>采购单号</th>
                                                <th>入库日期</th>
                                                <th>已使用次数</th>
                                                <th>修改</th>
                                                <th>删除</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr v-for="bean in beans">
                                                <td>{{bean.id}}</td>
                                                <td>{{bean.name}}</td>
                                                <td>{{bean.type}}</td>
                                                <td>{{bean.location}}</td>
                                                <td>{{bean.billno}}</td>
                                                <td>{{bean.regdate | formatDateFilter}}</td>
                                                <td>{{bean.usedCount}}</td>
                                                <td><a herf="#" @click="get(bean.id)"><span data-toggle="modal" data-target="#myModal"><img src="img/admin/edit.jpg" width="30" ></span></a></td>
                                                <td><a  herf="#" @click="deleteBean(bean.id)"><img src="img/admin/delete.jpg" width="30" ></a></td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            <div th:replace="include/admin/adminPage::html" ></div>



            <div class="modal fade" id="myModal"  data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <!-- <button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> -->
                            <h4 class="modal-title">修改工夹具{{bean.id}}信息</h4>
                        </div>
                        <div class="modal-body">
                            <div class="panel-body">
                                <table class="table table-hover" align="center" >

                                    <tr>
                                        <td>名称</td>
                                        <td><input    type="text"  v-model="bean.name" class="form-control" placeholder="请输入名称"></td>
                                    </tr>
                                    <tr>
                                        <td>型号</td>
                                        <td>
                                            <select name="" v-model="bean.type" class="form-control">
                                            <option value="大">大</option>
                                            <option value="中">中</option>
                                            <option value="小">小</option>
                                        </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>摆放位置</td>
                                        <td>
                                            <input    type="text"  v-model="bean.location" class="form-control" placeholder="请输入摆放位置">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>采购单号</td>
                                        <td><input    type="text"  v-model="bean.billno" class="form-control" placeholder="请输入采购单号"></td>
                                    </tr>

                                </table>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button data-dismiss="modal" class="btn btn-default" type="button" @click="clear">关闭</button>
                            <button  class="btn btn-default" type="button" @click="update">提交</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>




            <div align="center">
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal1">
                     添加数据
                </button>
            </div>
            <div class="modal fade" id="myModal1"  data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <!-- <button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> -->
                            <h4 class="modal-title">添加工夹具信息</h4>
                        </div>
                        <div class="modal-body">
                            <div class="panel-body">
                                <table class="table table-hover" align="center" >
                                    <tr >
                                        <td>编号</td>
                                        <td><input    type="text"  v-model="bean.id" class="form-control" placeholder="请输入编号"></td>
                                    </tr>
                                    <tr>
                                        <td>名称</td>
                                        <td><input    type="text"  v-model="bean.name" class="form-control" placeholder="请输入名称"></td>
                                    </tr>
                                    <tr>
                                        <td>型号</td>
                                        <td>
                                            <select class="indexSelect form-control" v-model="bean.type" >
                                                <option value="大">大</option>
                                                <option value="中">中</option>
                                                <option value="小">小</option>
                                            </select>

                                        </td>
                                    </tr>
                                    <tr>
                                        <td>摆放位置</td>
                                        <td>
                                            <input    type="text"  v-model="bean.location" class="form-control" placeholder="请输入摆放位置">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>采购单号</td>
                                        <td><input    type="text"  v-model="bean.billno" class="form-control" placeholder="请输入采购单号"></td>
                                    </tr>

                                </table>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button data-dismiss="modal" class="btn btn-default" type="button" >关闭</button>
                            <button  class="btn btn-default" type="button" @click="add">提交</button>

                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>



            <!--页脚部分-->
            <div th:replace="include/admin/adminFooter::html" ></div>
        </div>
    </div>
</div>



</body>
</html>
